Do you want to keep hackers out of your checking account?
Yes.
private
Visibility Modifier
When a member of a class is declared private it can
be used only by the methods of that class.
Here is the checking account class definition from the last
chapter with each of its variables declared to be private
.
class CheckingAccount { // data-declarations private String accountNumber; private String accountHolder; private int balance; //constructors CheckingAccount( String accNumber, String holder, int start ) { accountNumber = accNumber ; accountHolder = holder ; balance = start ; } // methods int currentBalance() { return balance ; } void processDeposit( int amount ) { balance = balance + amount ; } void processCheck( int amount ) { int charge; if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; } }
Now only the methods of a CheckingAccount object
can "see" the values in accountNumber, accountHolder,
and balance.